package com.gjy.redis.lua;

import com.gjy.redis.util.RedissonUtil;
import com.google.common.collect.Lists;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import redis.clients.jedis.Jedis;

/**
 * @author gjy
 * @version 1.0
 * @since 2024-05-24 22:29:33
 */
public class ScriptLuaTest {

    private static final Logger log = LoggerFactory.getLogger(ScriptLuaTest.class);
    private final Jedis jedis = RedissonUtil.jedisBasic();

    @Test
    public void test1() {
        String s = jedis.scriptLoad("if redis.call(\"get\", KEYS[1]) == ARGV[1] then\n" +
                "    return redis.call(\"del\", KEYS[1])\n" +
                "else\n" +
                "    return \"0\"\n" +
                "end");

        Object o = jedis.evalsha(s, Lists.newArrayList(Keys.StringKey.K1), Lists.newArrayList("7714773e-d3b4-4150-8594-de61d3a067a7"));
        log.info("o: {}", o);
    }

}
